#include "player.h"
#include <graphics.h>
#include <iostream>
using namespace std;
int number[] = {
	BLUE,
	GREEN,
	CYAN,
	RED,
	MAGENTA,
	BROWN,
	LIGHTGRAY,
	DARKGRAY,
	LIGHTBLUE,
	LIGHTGREEN,
	LIGHTCYAN,
	LIGHTRED,
	LIGHTMAGENTA,
	YELLOW,
	WHITE 
};
void Player::Draw() {
	circle(x, y, radius);
}
Player::Player() {
	x = y = 10;
	radius = 5;
}
Player::Player(int x, int y, int radial = 5) {
	this->x = x;
	this->y = y;
	this->radius = radial;
}
void Player::Move(int x, int y) {
	color_t tmp = getcolor();
	setcolor(getbkcolor());
	Draw();
	setcolor(color);
	this->x = x;
	this->y = y;
	Draw();
	setcolor(tmp);
}
void Player::State() {
	//横坐标为x,纵坐标为y
	if (keystate(key_A))
		if (x - radius - MOVE_DISTACE >= 0)Move(this->x - MOVE_DISTACE, this->y);
	if (keystate(key_D))
		if (x + radius + MOVE_DISTACE <= WIDTH)Move(this->x + MOVE_DISTACE, this->y);
	if (keystate(key_S))
		if (y + radius + MOVE_DISTACE <= HIGHT)Move(this->x, this->y + MOVE_DISTACE);
	if (keystate(key_W) || keystate(key_space)) {
		timeofdrop = 0;
		if (y - radius - MOVE_DISTACE >= 0)Move(this->x, this->y - MOVE_DISTACE);
	}
	if (keystate(key_F))
		DO_PHYSICS_MOVING ^= 1;
	if (keystate(key_R)) {
		color_number++;
		color_number %= 15;
		color = number[color_number];
		color_t tmp = getcolor();
		setcolor(color);
		Draw();
		setcolor(tmp);
	}
	timeofdrop += .5;
	if (y + radius + NOW_SPEED <= HIGHT)Move(this->x, this->y + NOW_SPEED);
	else {
		/*
		if(DO_PHYSICS_MOVING){
		int cnt=0;
		while(timeofdrop>1){
			cnt++;
			cout<<timeofdrop<<endl;
			Move(this->x,this->y-NOW_SPEED/2);
			timeofdrop-=3;
			Sleep(10);
			if(cnt==4)break;
		}
		timeofdrop=-3;
		}
		*/
	}
}
